﻿using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using WMSUIMVC.DTO.Client;
using WMSUIMVC.DTO.CusContact;
using WMSUIMVC.DTO.Vendor;
using XuanKeZz.Application.HTTP;

namespace WMSUIMVC.Controllers
{
    public class ClientController : Controller
    {
        protected readonly IConfiguration _configuration;

        public ClientController(IConfiguration configuration)
        {
            _configuration = configuration;
        }
        public IActionResult Index()
        {
            return View();
        }
        /// <summary>
        ///客户列表
        /// </summary>
        /// <returns></returns>
        public IActionResult ShowClient()
        {
            return View();
        }
        #region 客户
        /// <summary>
        /// /客户下拉框
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        public async Task<IActionResult> GetDropClient(string Token)
        {
            HttpClientWrapper client = new HttpClientWrapper(Token);
            string url = _configuration["Url"] + "ywd/api/ClientRead/GetDropClient";
            string res = await client.GetAsync(url);
            return Json(res);
        }
        /// <summary>
        /// 客户显示
        /// </summary>
        /// <param name="showclient"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetClientShow(SelClientDTO showclient)
        {
            HttpClientWrapper client = new HttpClientWrapper(showclient.Token);
            string url = _configuration["Url"] + "ywd/api/ClientRead/GetClient?ClientCode=" + showclient.ClientCode + "&ClientName=" + showclient.ClientName + "&Landline=" + showclient.Landline + "&Office_Id=" + showclient.Office_Id + "&pageindex=" + showclient.PageIndex + "&pagesize=" + showclient.PageSize;
            string GetClient = await client.GetAsync(url);
            return Json(GetClient);
        }
        /// <summary>
        /// 添加客户信息
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> AddClients(AddClientDTO obj)
        {
            HttpClientWrapper client = new HttpClientWrapper(obj.Token);
            string url = _configuration["Url"] + "ywx/api/Client/AddClient";
            string datas = JsonConvert.SerializeObject(obj);
            var res = await client.PostAsync(url, datas);
            return Json(res);
        }
        /// <summary>
        /// 批量删除客户
        /// </summary>
        /// <param name="delclient"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> DelAllClient(DelClientDTO delclient)
        {
            HttpClientWrapper client = new HttpClientWrapper(delclient.Token);
            string url = _configuration["Url"] + "ywx/api/Client/DelClient";
            string list = JsonConvert.SerializeObject(delclient);
            var res = await client.PostAsync(url, list);
            return Json(res);
        }
        /// <summary>
        /// 反填客户
        /// </summary>
        /// <param name="fclient"></param>
        /// <returns></returns>
        public async Task<IActionResult> GetClientFt(FanClientDTO fclient)
        {
            HttpClientWrapper client = new HttpClientWrapper(fclient.Token);
            string url = _configuration["Url"] + "ywd/api/ClientRead/GetClientCusContactById?ClientId=" + fclient.ClientId;
            string GetUnit = await client.GetAsync(url);
            return Json(GetUnit);
        }
        /// <summary>
        /// 修改客户
        /// </summary>
        /// <param name="uclient"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<IActionResult> UpdClient(UpdClientDTO uclient)
        {
            HttpClientWrapper client = new HttpClientWrapper(uclient.Token);
            string url = _configuration["Url"] + "ywx/api/Client/UpdClient";
            string list = JsonConvert.SerializeObject(uclient);
            string UpdVendor = await client.PutAsync(url, list);
            return Json(UpdVendor);
        }
        #endregion
        #region 客户联系人
        /// <summary>
        /// 客户联系人显示
        /// </summary>
        /// <param name="showcuscontact"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ActionResult> GetCusContactShow(SelectCusContact showcuscontact)
        {
            HttpClientWrapper client = new HttpClientWrapper(showcuscontact.Token);
            string url = _configuration["Url"] + "ywd/api/CusContactRead/GetCusContact";
            string GetClient = await client.GetAsync(url);
            return Json(GetClient);
        }
        /// <summary>
        /// 添加客户联系人信息
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<ActionResult> AddCusContacts(AddCusContact obj)
        {
            HttpClientWrapper client = new HttpClientWrapper(obj.Token);
            string url = _configuration["Url"] + "ywx/api/CusContact/AddCusContact";
            string datas = JsonConvert.SerializeObject(obj);
            var res = await client.PostAsync(url, datas);
            return Json(res);
        }
        /// <summary>
        /// 客户联系人批量删除
        /// </summary>
        /// <param name="vendor"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<IActionResult> DelAllCusContact(DelCusContact delcuscontact)
        {
            HttpClientWrapper client = new HttpClientWrapper(delcuscontact.Token);
            string url = _configuration["Url"] + "ywx/api/CusContact/DelCusContact";
            string list = JsonConvert.SerializeObject(delcuscontact);
            var res = await client.PutAsync(url, list);
            return Json(res);
        }
        /// <summary>
        /// 反填客户联系人
        /// </summary>
        /// <param name="fvendor"></param>
        /// <returns></returns>
        public async Task<IActionResult> GetCusContactFt(FanClientDTO fclient)
        {
            HttpClientWrapper client = new HttpClientWrapper(fclient.Token);
            string url = _configuration["Url"] + "ywd/api/CusContactRead/GetCusContactById?CusContactId=" + fclient.ClientId;
            string GetUnit = await client.GetAsync(url);
            return Json(GetUnit);
        }
        /// <summary>
        /// 修改客户联系人
        /// </summary>
        /// <param name="uvendor"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<IActionResult> UpdCusContact(UpdCusContact ucuscontact)
        {
            HttpClientWrapper client = new HttpClientWrapper(ucuscontact.Token);
            string url = _configuration["Url"] + "ywx/api/CusContact/UpdCuscontact";
            string list = JsonConvert.SerializeObject(ucuscontact);
            string UpdVendor = await client.PutAsync(url, list);
            return Json(UpdVendor);
        }
        #endregion
    }
}
